home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / rexx / imc / rexx-imc.5 / functions.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-25  |  10.9 KB  |  165 lines

  1. /* The functions of REXX/imc            This is a 132 column file            (C) Ian Collier 1992 */
  2.  
  3. #include"const.h"
  4.  
  5. #ifdef __STDC__     /* define Args macro so that the arguments of each */
  6. #define Args(a) a   /* function can be stated without confusing the */
  7. #else               /* compiler */
  8. #define Args(a) ()
  9. #define volatile    /* Ignore "volatile" for traditional C compiler */
  10. #endif
  11.  
  12. #ifdef DEBUG /* Debugging mtest routines */
  13. int mtest_debug Args((char **memptr,unsigned *alloc,unsigned length,unsigned extend,long *diff));
  14. #define mtest(memptr,alloc,length,extend) (mtest_debug(&memptr,&alloc,length,extend,(long *)0))
  15. #define dtest(memptr,alloc,length,extend) (mtest_debug(&memptr,&alloc,length,extend,&mtest_diff))
  16. #else /* not defined DEBUG */
  17. /* Usually the mem test routines use inline code for greater efficiency.
  18.    mtest: reallocate an area only if it is too small
  19.    dtest: the same, but also return 1 if the area moved and set mtest_diff to
  20.           the difference
  21.    Recently fixed to save the old value when realloc fails
  22. */
  23. #define mtest(memptr,alloc,length,extend) {char *old;         \
  24.         (alloc<(length))&&(                                   \
  25.     old=memptr,                                           \
  26.         (memptr=realloc(memptr,(unsigned)(alloc+=(extend))))||(memptr=old,die(Emem),1)  \
  27.         );}
  28. #define dtest(memptr,alloc,length,extend) (                   \
  29.         (alloc<(length))&&(                                   \
  30.         mtest_old=memptr,                                     \
  31.         (memptr=realloc(memptr,(unsigned)(alloc+=(extend))))||(memptr=mtest_old,die(Emem),1), \
  32.         mtest_diff=memptr-mtest_old ))                      
  33. #endif /* DEBUG */
  34.  
  35. #define whattype(c)      (types[(unsigned char)(c)])
  36. #define alphanum(c)      (alphs[(unsigned char)(c)])
  37. #define rexxsymboldot(c) (whattype(c)>0)
  38. #define rexxsymbol(c)    (symbs[(unsigned char)(c)])
  39.  
  40. #ifdef NO_LDL                                    /* Declare the dynamic load functions */
  41. void *dlopen Args((char*,int));                            /* either in situ or from the system header file */
  42. void *dlsym Args((void *,char*));
  43. char *dlerror Args((void));
  44. int dlclose Args((void*));
  45. #else
  46. #include<dlfcn.h>
  47. #endif /* NO_LDL */
  48.  
  49. /* in rexx.c */
  50. int main Args((int argc, char *argv[]));
  51. char *allocm Args((unsigned size));
  52. void die Args((int rc));
  53. static char *interpreter Args((int *anslen,int start,                           /* Interpret program lines */
  54.                         char *callname,char *howcall,char *args[],int arglen[],int inherit,int delay));
  55. static void doaddress Args((char **line,char *env));                /* Address a command to an environment */
  56. static void parse Args((char *list[],int len[],int up,char *line,int *ptr));    /* PARSE strings with a template */
  57. static char uc1 Args((int c,int up));                        /* Uppercase c, if up */
  58. static void pset1 Args((char *list,int listlen,char *val,int len,int up));    /* Tokenise a string into variables */
  59. static void pset Args((char *varname,int namelen,char *val,int len,int up));    /* Assign a PARSE result to a variable */
  60. static int findsigl Args((int *level));                        /* Find most recent line number */
  61. static void getcallargs Args((char *args[],int arglen[],int argc));        /* Unstack parameters in a CALL instruc */
  62. int rxcall Args((int stmt,char *name,int argc,int lit,char *how));        /* Call a procedure */
  63. char *rxinterp Args((char *exp,int len,int *rlen,char *name,char *how,        /* INTERPRET a string */
  64.                      char *args[],int arglen[]));
  65. static void doconds Args((void));                        /* Check for delayed conditions and trap them */
  66. void settrace Args((char *));                            /* Set trace according to the given option */
  67. static int setoption Args((char *option,int len));                /* Set an option from the OPTIONS instruction */
  68. static int gettrap Args((char **lineptr,int on,int *stmt));            /* Get a trap name after "call/signal on" */
  69. static void testvarname Args((char **line,char *var,int len));                  /* Test the symbol against a stored name */
  70. static void skipstmt Args((void));                        /* Skip the current instruction */
  71. static void stepdo Args((void));                        /* Step past the current DO */
  72. static void stepselect Args((void));                        /* Step past the current SELECT */
  73. static void stepif Args((void));                        /* Step past the current IF */
  74. static void stepwhen Args((void));                        /* Step past the current WHEN */
  75. static void findend Args((void));                        /* Find the next END */
  76. static void halt_handler();                            /* handle halt signals */
  77. static void error_handler();                            /* handle error signals */
  78. static void sigtrace Args((void));                        /* Go into trace mode, or exit */
  79. static int killself Args((int sig));                        /* Kill oneself after an emergency stop */
  80.  
  81. /* in calc.c */
  82.  
  83. char *scanning Args((char *line,int *ptr,int *len));                /* Evaluate an expression */
  84. void tracelast Args((char *type));                        /* Trace the last value on the stack */
  85. void traceline Args((char *type,char *exp,int len));                /* Trace any string */
  86. void stack Args((char *exp,int len));                        /* Stack a string literally */
  87. void stackq Args((char *exp,int len,int quote));                /* Stack a string, collapsing quotes */
  88. void stackx Args((char *exp,int len));                        /* Stack a hex constant */
  89. void stackb Args((char *exp,int len));                        /* Stack a binary constant */
  90. void stackint Args((int i));                            /* Stack an integer */
  91. void stacknull Args((void));                            /* Stack a null parameter */
  92. void binplus Args((int op));                            /* Add the last two values */
  93. void binmin Args((int op));                            /* Subtract the last value from the previous */
  94. void binmul Args((int op));                            /* Multiply the last two values */
  95. void bindiv Args((int op));                            /* Divide the previous value by the last */
  96. void binexp Args((int op));                            /* Raise the previous value to the last-th power */
  97. void rxdup Args((void));                            /* Duplicate the last value */
  98. void binrel Args((int op));                            /* Compare the last two values */
  99. void binbool Args((int op));                            /* Combine the last two logical values */
  100. void bincat Args((int op));                            /* Concatenate the last two values */
  101. void unnot Args((int op));                            /* Negate logically the last value */
  102. void unmin Args((int op));                            /* Negate arithmetically the last value */
  103. void unplus Args((int op));                            /* Reformat the last numeric value */
  104. void strip Args((void));                            /* Strip surrounding space from the last value */
  105. int num Args((int *minus,int *exp,int *zero,int *len));                /* Get the last value as a number */
  106. int getint Args((int flg));                            /* Get the last value as an integer */
  107. int isint Args((int num,int len,int exp));                    /* Is the last value an integer? */
  108. char *delete Args((int *len));                            /* Delete and return the last value */
  109. int isnull Args((void));                            /* Is the last value null? */
  110. void stacknum Args((char *num,int len,int exp,int minus));            /* Stack a number */
  111. void getvarname Args((char *line,int *ptr,char *varname,int *namelen,int maxlen)); /* Get a symbol from a program line */
  112. void skipvarname Args((char *line,int *ptr));                    /* Skip a symbol in a program line */
  113. int gettoken Args((char *line,int *ptr,char *varname,int maxlen,int ex));    /* Get a token from a program line */
  114.  
  115. /* in util.c */
  116. char *message Args((int rc));                                /* Return an error message string */
  117. void rcset Args((int i,int type,char *desc));                        /* Set the variable rc to the given value */
  118. void printrc Args((int i));                                /* Print a return code */
  119. char *varsearch Args((char *name,int len,int *level,int *exist));            /* Search for a simple symbol or stem */
  120. char *tailsearch Args((char *stem,char *name,int len,int *exist));            /* Search for a tail within a stem */
  121. char *valuesearch Args((char *name,int namelen,int *level,int *exist,char **stem)); /* Search for any variable */
  122. void printtree Args((int lev));                                /* Print the entire variable table */
  123. void update Args((int value,int amount,int level));                    /* Update the pointers for a variable level */
  124. void varcreate Args((char *varptr,char *name,char *value,int namelen,int len,int lev));/* Create a simple symbol */
  125. void stemcreate Args((char *varptr,char *name,char *value,int namelen,int len,int lev));/* Create a stem */
  126. void tailcreate Args((char *stem,char *tailptr,char *name,char *value,int namelen,int len,int level));/* Create a tail in a stem */
  127. void varset Args((char *name,int varlen,char *value,int len));                /* Assign any value to any variable */
  128. char *varget Args((char *name,int varlen,int *len));                    /* Get any variable's value */
  129. void newlevel Args((void));                                /* Make a new level in the variable table */
  130. void varcopy Args((char *name,int varlen));                        /* Expose a variable from the previous level */
  131. void vardup Args((void));                                /* Duplicate the entire variables level */
  132. void vardel Args((char *name,int len));                            /* Remove one of the duplicate variables */
  133. char uc Args((int c));                                    /* Uppercase a character */
  134. void *pstack Args((int type,int len));                            /* Make a new program stack entry */
  135. int unpstack Args((void));                                /* Examine the top program stack entry */
  136. void *delpstack Args((void));                                /* Delete and return the top p-stack entry */
  137. int strcmpi Args((char *s1,char *s2));                            /* Is s1 an initial substring of s2? */
  138. void printstmt Args((int stmt,int after,int error));                    /* Print a source statement */
  139. void freestack Args((void *ptr,int i));                            /* Clean up after deleting a p-stack entry */
  140. void interactive Args((void));                                /* Pause execution, if in interactive trace */
  141. void tokenise Args((char *input,int ilen,int dolabels,int line1));            /* Preprocess source code */
  142. char *load Args((char *name,int *sourcelen));                        /* Load a program from disk */
  143. void process Args((int c));                                /* Tokenise characters */
  144. void expand Args((int c));                                /* Expand a token */
  145. void display Args((int line,int ptr));                            /* Display a program line */
  146. int which Args((char *gn,int opt,char *fn));                        /* Search for a program or subroutine */
  147. char *hashsearch Args((int hash,char *name,int *exist));                /* Search for a hash table entry */
  148. void *hashget Args((int hash,char *name,int *exist));                    /* Return the value associated with a key */
  149. void **hashfind Args((int hash,char *name,int *exist));                    /* Return a pointer to a key's value element */
  150. struct fileinfo *fileinit Args((char *name,char *filename,FILE *fp));            /* Store an open file's details */
  151. void funcinit Args((char *name,void *handle,int (*address)()));                /* Store an external function's details */
  152. int fileclose Args((char *name));                            /* Free a file's hash table entry */
  153. void hashfree Args((void));                                /* Free all memory used by hash tables */
  154.  
  155. /* in rxfn.c */
  156. int rxfn Args((char *name,int argc));                            /* Try to call a builtin function */
  157. int rxseterr Args((struct fileinfo *f,char *name));                    /* Set rc to indicate a file's status */
  158. char *undelete Args((int *l));                                /* Get last value without deleting it */
  159.  
  160. /* in shell.c */
  161. int shell Args((char *command));                            /* Interpret a shell command */
  162. void hashclear Args((void));                                /* Clear the shell's hashed path table */
  163.  
  164. #undef Args
  165.